home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3460 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.3 KB

  1. Path: cville-srv.wam.umd.edu!leungyl
  2. From: leungyl@wam.umd.edu (David Leung)
  3. Newsgroups: comp.lang.c++
  4. Subject: Need help in C
  5. Date: 24 Jan 1996 05:45:45 GMT
  6. Organization: University of Maryland College Park
  7. Message-ID: <4e4h29$3f2@cville-srv.wam.umd.edu>
  8. NNTP-Posting-Host: rac1.wam.umd.edu
  9. X-Newsreader: TIN [version 1.2 PL0]
  10.  
  11. I am studying C/C++ and I arrived at a problem that I am stuck with.
  12. I think it is easy for expericenced programmers, if you can help me
  13. please email me at leungyl@wam.umd.edu
  14.  
  15. this is the problem
  16.  
  17. input a five digit number
  18.  
  19. then, separate the five digits into 5 separate numbers and evaluate them
  20. independently. Basically, cut the number into five pieces. This is what
  21. I wrote.....
  22.  
  23. cout <<  "Enter a five digit number: ";
  24.  
  25. cin >> input;
  26.  
  27.  
  28.  
  29. digi1 = input / 10000;
  30.  
  31. digi2 = input / 1000 - digi1 * 10;
  32.  
  33. digi3 = input / 100 - digi1 * 100 - digi2 * 10;
  34.  
  35. digi4 = input / 10 - digi1 * 1000 - digi2 * 100 - digi3 * 10;
  36.  
  37. digi5 = input - digi1 * 10000 - digi2 * 1000 - digi3 * 100 - digi4 * 10;
  38.  
  39.  
  40.  
  41. cout << input << endl;
  42.  
  43. cout << digi1 << endl;
  44.  
  45. cout << digi2 << endl;
  46.  
  47. cout << digi3 << endl;
  48.  
  49. cout << digi4 << endl;
  50.  
  51. cout << digi5 << endl;
  52.  
  53.  
  54.  
  55.  
  56.  
  57. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  58. the problem is, it work for some numbers, but for others it doesn't work.
  59. Why? Can somebody help me??Thanks very much.
  60.  
  61.  
  62. Regards,
  63.  
  64.  
  65. David
  66.  
  67.